package org.rabbit.web;

import javax.annotation.Resource;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;

import org.rabbit.pojo.User;
import org.rabbit.service.UserServive;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.dubbo.config.annotation.Reference;

@RestController
@CrossOrigin(value= {"*"},allowCredentials="true")
public class UserController {
	
	@Resource
	private RedisTemplate<String,User> redisTemplate;

	@Reference
	private UserServive us;
	
	/*@RequestMapping("register")
	public String register(User u) {
		us.register(u);
		return "ok";
	}*/
	
	
	@RequestMapping("/login")
	public String login(User u,HttpServletResponse response) {
		String tokenId =us.login(u);
		String re=null;
		
		if(tokenId!=null) { //redis里面有值
			Cookie cookie = new Cookie("token", tokenId);
			cookie.setDomain("localhost");
			cookie.setPath("/");
			response.addCookie(cookie);
			re="ok";
		}
		
		return re;
	}
}
